//+------------------------------------------------------------------+ //| JC - Line Break Alert.mq4 | //| Juan Carlos Christensen. | //| http://www.eumefinancial.com | //|Modified on June 8, 2007 by Hartono Setiono | //|Movable Price Level Setting by Line | //|Store & Restore Setting to File | //+------------------------------------------------------------------+ #property copyright "Juan Carlos Christensen." #property link "http://www.eumefinancial.com" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Blue #property indicator_width1 2 //---- input parameters extern double Price1 = 0.0000; extern double Price2 = 0.0000; extern string Modes = "0- Line; 1- Channel"; extern int Mode = 1; extern bool UseSoundAlert = True; extern string SoundFile = "alert.wav"; extern int PlaySoundNTimes = 1; extern bool UseAlertPopUp = True; extern bool UseTickMode = True; extern bool UseSendMail = False; extern bool DeactivateOnAlert = True; extern color price1_color = Blue; extern color price2_color = Red; bool DidBreakout = False; double LastPrice; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators if(Price1==0 && Price2==0) RestoreSetting(); LastPrice=Bid; CreateLine("price1",price1_color,Price1); if(Mode==1) CreateLine("price2",price2_color,Price2); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- if(Price1!=0 && Price2!=0) StoreSetting(); ObjectDelete("price1"); ObjectDelete("price2"); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- double aPrice1=ObjectGet("price1",OBJPROP_PRICE1); if(GetLastError()==4202) CreateLine("price1",price1_color,Price1); if(aPrice1!=0 && aPrice1 != Price1) {Price1=aPrice1; Print("Price1 Changed:",Price1); DidBreakout=false;} if(Mode==1) { double aPrice2=ObjectGet("price2",OBJPROP_PRICE1); if(GetLastError()==4202) CreateLine("price2",price2_color,Price2); if(aPrice2!=0 && aPrice2 != Price2) {Price2=aPrice2; Print("Price2 Changed:",Price2); DidBreakout=false;} } if(Price1= Price1)) || ((LastPrice > Price1) && (CurrentPrice <= Price1)) && !DidBreakout) { if(DeactivateOnAlert) DidBreakout = True; if(UseSoundAlert) for(int x=0;x<=PlaySoundNTimes;x++) PlaySound(SoundFile); if(UseAlertPopUp) Alert(Symbol()," ",Period(),"Price Crossing Alert Line at ", Price1); //Symbol()," ",Period()," @ ",Bid if(UseSendMail) SendMail("Price Crossing Alert Line at " + Price1 + "!", "This is an email from the JC - Line Break Alert indicator. Price is crossing your alert line at " + Price1 + "!"); } } //+------------------------------------------------------------------+ void ChannelBreakOut() { double CurrentPrice=Bid; if((LastPrice < Price1) && (CurrentPrice >= Price1) && !DidBreakout) { if(DeactivateOnAlert) DidBreakout = True; if(UseSoundAlert) for(int x=0;x<=PlaySoundNTimes;x++) PlaySound(SoundFile); if(UseAlertPopUp) Alert(Symbol()," ",Period(),"Price Breaking Up at ", Price1); if(UseSendMail) SendMail("Channel Breaking Up at " + Price1 + "!", "This is an email from the JC - Line Break Alert indicator. Price broke up your channel alert line at " + Price1 + "!"); } if((LastPrice > Price2) && (CurrentPrice <= Price2) && !DidBreakout) { if(DeactivateOnAlert) DidBreakout = True; if(UseSoundAlert) for(x=0;x<=PlaySoundNTimes;x++) PlaySound(SoundFile); if(UseAlertPopUp) Alert(Symbol()," ",Period(),"Price Breaking Down at ", Price2); if(UseSendMail) SendMail("Channel Breaking Down at " + Price2 + "!", "This is an email from the JC - Line Break Alert indicator. Price broke down your channel alert line at " + Price2 + "!"); } } //+------------------------------------------------------------------+ void CreateLine(string aName, color aColor, double aPrice) { ObjectCreate(aName, OBJ_HLINE, 0, Time[0],aPrice); ObjectSet(aName, OBJPROP_COLOR, aColor); ObjectSet(aName, OBJPROP_STYLE, STYLE_DASH); } void StoreSetting() { int myhandle; Print("Store Setting :",Symbol(),":",Price1,":",Price2,":",Mode); myhandle=FileOpen("LineBreak_"+Symbol()+".SET", FILE_BIN|FILE_WRITE|FILE_READ); if(myhandle>0) { FileSeek(myhandle,0,0); FileWriteDouble(myhandle, Price1); FileWriteDouble(myhandle, Price2); FileWriteInteger(myhandle, Mode); FileClose(myhandle); } } void RestoreSetting() { int myhandle, aMode, err; double aPrice1, aPrice2; myhandle=FileOpen("LineBreak_"+Symbol()+".SET", FILE_BIN|FILE_WRITE|FILE_READ); if(myhandle>0) { FileSeek(myhandle,0,0); aPrice1=FileReadDouble(myhandle); err=GetLastError(); if(err==0) { aPrice2=FileReadDouble(myhandle); err=GetLastError();} if(err==0) { aMode=FileReadInteger(myhandle); err=GetLastError();} FileClose(myhandle); } if(err==0){Mode=aMode; Price1=aPrice1; Price2=aPrice2;} Print("Restore Setting :",Symbol(),":",err,":",aPrice1,":",aPrice2,":",aMode); }